package com.xiaoxing.zhinenghuacangku_zhijian.mvp.ui.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.dds.soap.SoapListener;
import com.dds.soap.SoapParams;
import com.dds.soap.SoapUtil;
import com.dothantech.lpapi.IAtBitmap;
import com.dothantech.lpapi.LPAPI;
import com.dothantech.printer.IDzPrinter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.BaseConstants;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.xiaoxing.zhinenghuacangku_zhijian.R;
import com.xiaoxing.zhinenghuacangku_zhijian.R2;
import com.xiaoxing.zhinenghuacangku_zhijian.di.component.DaggerFengQianLieBiaoComponent;
import com.xiaoxing.zhinenghuacangku_zhijian.di.module.FengQianLieBiaoModule;
import com.xiaoxing.zhinenghuacangku_zhijian.mvp.contract.FengQianLieBiaoContract;
import com.xiaoxing.zhinenghuacangku_zhijian.mvp.presenter.FengQianLieBiaoPresenter;
import com.xiaoxing.zhinenghuacangku_zhijian.mvp.ui.adapter.FengQianLieBiaoAdapter;
import com.xiaoxing.zhinenghuacangku_zhijian.mvp.ui.entity.FengQianLieBiao;
import com.xiaoxing.zhinenghuacangku_zhijian.mvp.ui.entity.GetSimpleZoneBuffer;
import com.xiaoxing.zhinenghuacangku_zhijian.mvp.ui.utils.PrinterUtil;

import org.ksoap2.SoapFault;
import org.ksoap2.serialization.SoapObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;
import com.jess.arms.utils.CProgressDialogUtils;
import me.jessyan.armscomponent.commonres.utils.ToolbarUtils;
import me.jessyan.armscomponent.commonres.view.NiceSpinner;
import me.jessyan.armscomponent.commonres.view.RecycleViewDivider;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.commonsdk.utils.ButtonUtils;

import static com.jess.arms.utils.Preconditions.checkNotNull;


@Route(path = RouterHub.ZHI_NENG_HUA_CANG_KU_ZHI_JIAN_ACTIVITY_FENG_QIAN_LIE_BIAO)
public class FengQianLieBiaoActivity extends BaseActivity<FengQianLieBiaoPresenter> implements FengQianLieBiaoContract.View, OnRefreshListener, FengQianLieBiaoAdapter.IFengQianLieBiaoAdapter, PrinterUtil.PrinterI {


    private static boolean mIsNeedDemo = true;
    @BindView(R2.id.empty_text)
    TextView empty_text;
    @BindView(R2.id.empty_image)
    ImageView empty_image;

    @BindView(R2.id.empty)
    View mEmptyLayout;
    @BindView(R2.id.recyclerView)
    RecyclerView mRecyclerView;
    @BindView(R2.id.refreshLayout)
    RefreshLayout mRefreshLayout;
    PrinterUtil mPrinterUtil;
    private FengQianLieBiaoAdapter mAdapter;
    private List<FengQianLieBiao> mDataBeanList = new ArrayList<>();
    private AlertDialog mAlertDialog;
    private String mSelectedBufferId;
    private String mSelectedBufferName;
    private Disposable disposable;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerFengQianLieBiaoComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .fengQianLieBiaoModule(new FengQianLieBiaoModule(this))
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_feng_qian_lie_biao; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {

        ToolbarUtils.initToolbarTitleBack(this, getString(R.string.activity_feng_qian_lie_biao));
        initPrinter();
        initRefreshLayout();
        initRecyclerView();
        initEmpty();
        maskListForQuality();
        startTimer();

    }

    private void initPrinter() {
        mPrinterUtil = new PrinterUtil(this);
        mPrinterUtil.setPrinterI(this);
        IDzPrinter.Factory.getInstance().init(this, mPrinterUtil.mCallback);
    }

    private void initRefreshLayout() {
        mRefreshLayout.setRefreshHeader(new
                ClassicsHeader(this).setSpinnerStyle(SpinnerStyle.FixedBehind).setPrimaryColorId(R.color.public_colorPrimary).setAccentColorId(android.R.color.white));
        mRefreshLayout.setOnRefreshListener(this);
        mRefreshLayout.setEnableRefresh(false);
        mRefreshLayout.autoRefresh();
        mRefreshLayout.setEnableLoadMore(false);
    }

    private void initRecyclerView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(FengQianLieBiaoActivity.this));
        mRecyclerView.addItemDecoration(new RecycleViewDivider(this, LinearLayoutManager.VERTICAL, 10, Color.parseColor("#EEEEEE")));

        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setAdapter(mAdapter = new FengQianLieBiaoAdapter(FengQianLieBiaoActivity.this, mDataBeanList, this));

        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
            }
        });
    }

    private void initEmpty() {
        empty_image.setImageResource(R.drawable.ic_empty);
        empty_text.setTextColor(Color.parseColor("#CFCFCF"));
        empty_text.setText("暂无数据");
    }

    /**
     * @param
     * @return
     * @method
     * @description 任务列表
     * @date: 2020/9/3 0003 21:52
     * @author: 小星
     */
    private void maskListForQuality() {
        mDataBeanList.clear();
        mAdapter.notifyDataSetChanged();
        mEmptyLayout.setVisibility(View.VISIBLE);
        mRecyclerView.setVisibility(View.GONE);
        showLoading();

        String methodNames = "MaskListForQuality";
        SoapParams paramss = null;
        paramss = new SoapParams();

        SoapUtil.getInstance(getContext()).callEntry(getUrl(), BaseConstants.NAME_SPACE, methodNames, paramss, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {
                hideLoading();
                try {
                    String result = object.getProperty(methodNames + "Result").toString();
                    if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                        List<FengQianLieBiao> fengQianLieBiaos = ArmsUtils.parseString2List(result, FengQianLieBiao.class);

                        if (fengQianLieBiaos != null && fengQianLieBiaos.size() > 0) {
                            mDataBeanList.clear();
                            mDataBeanList.addAll(fengQianLieBiaos);
                            mAdapter.notifyDataSetChanged();
                            mEmptyLayout.setVisibility(View.GONE);
                            mRecyclerView.setVisibility(View.VISIBLE);
                        } else {
                            mEmptyLayout.setVisibility(View.VISIBLE);
                            mRecyclerView.setVisibility(View.GONE);
                        }

                    } else {

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
                hideLoading();
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
                hideLoading();

            }
        }, getAapiUserName(), getApiPwd());
    }

    /**
     * 开始定时执行
     */
    private void startTimer() {
        stopTimer();
        disposable = Observable.interval(60, TimeUnit.SECONDS)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(@io.reactivex.annotations.NonNull Long aLong) throws Exception {
                        // 逻辑代码
                        maskListForQuality();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(@io.reactivex.annotations.NonNull Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });
    }

    @Override
    public void showLoading() {
        CProgressDialogUtils.showProgressDialog(this);
    }

    /**
     * 停止定时执行
     */
    protected void stopTimer() {
        if (null != disposable) {
            disposable.dispose();
            disposable = null;
        }
    }

    @Override
    public void hideLoading() {
        CProgressDialogUtils.cancelProgressDialog(this);
    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.makeText(this, message);

    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        stopTimer();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

        //getFengQianLieBiaoList();
        mRefreshLayout.finishRefresh();
        mEmptyLayout.setVisibility(View.GONE);

    }

    @Override
    public void getFengQianLieBiaoDataSuccess(FengQianLieBiao entityList) {

//        if (entityList != null && entityList.getData() != null && entityList.getData().size() > 0) {
//            mDataBeanList.clear();
//            mDataBeanList.addAll(entityList.getData());
//            mAdapter.notifyDataSetChanged();
//            mEmptyLayout.setVisibility(View.GONE);
//            mRecyclerView.setVisibility(View.VISIBLE);
//        } else {
//            mEmptyLayout.setVisibility(View.VISIBLE);
//            mRecyclerView.setVisibility(View.GONE);
//        }

    }

    private void getFengQianLieBiaoList() {
        HashMap<String, String> map = new HashMap<>();

        mPresenter.getFengQianLieBiaoList(map);
    }

    @Override
    public void shengChengFengQianMa(FengQianLieBiao fengQianLieBiao) {
        if (mPrinterUtil.selectPrinterCheck()) {
            createMaskCode(fengQianLieBiao.getMonthid());
        } else {
            showMessage("请先连接二维码打印机");
        }
    }

    @Override
    public void songJian(FengQianLieBiao fengQianLieBiao) {
        getSimpleTestZoneBuffer(fengQianLieBiao);
    }

    private void getSimpleTestZoneBuffer(FengQianLieBiao fengQianLieBiao) {
        showLoading();

        String methodNames = "GetSimpleTestZoneBuffer";
        SoapParams paramss = null;
        paramss = new SoapParams();

        SoapUtil.getInstance(getContext()).callEntry(getUrl(), BaseConstants.NAME_SPACE, methodNames, paramss, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {
                hideLoading();
                try {
                    String result = object.getProperty(methodNames + "Result").toString();
                    if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {

                        showQuYangQu(result, fengQianLieBiao);

                    } else {

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
                hideLoading();
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
                hideLoading();

            }
        }, getAapiUserName(), getApiPwd());
    }

    private void showQuYangQu(String result, FengQianLieBiao fengQianLieBiao) {


        View myView = LayoutInflater.from(this).inflate(R.layout.zhi_neng_cang_ku_zhi_jian_layout_qu_yang_qu, null);
        NiceSpinner niceSpinner = myView.findViewById(R.id.nice_position);
        List<GetSimpleZoneBuffer> getSimpleZoneBuffers = new Gson().fromJson(result, new TypeToken<List<GetSimpleZoneBuffer>>() {
        }.getType());

        if (getSimpleZoneBuffers != null && getSimpleZoneBuffers.size() > 0) {
            initSpPosition(getSimpleZoneBuffers, niceSpinner);
        }

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setPositiveButton("agv发运", null);
        builder.setNeutralButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.setNegativeButton("人工发运", null);
        mAlertDialog = builder.create();
        mAlertDialog.setTitle("选择取样区");
        mAlertDialog.setView(myView);
        mAlertDialog.show();


        //拿到按钮并判断是否是POSITIVEBUTTON，然后我们自己实现监听
        mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!ButtonUtils.isFastDoubleClick()) {

                    sendAGVFromMaskToTestOrder(fengQianLieBiao);
                    mAlertDialog.dismiss();
                } else {
                    showMessage("10s内请勿重复点击");
                }

            }
        });
        mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!ButtonUtils.isFastDoubleClick()) {

                    peopleSendFromMaskToTestOrder(fengQianLieBiao);
                    mAlertDialog.dismiss();
                } else {
                    showMessage("10s内请勿重复点击");
                }

            }
        });


    }

    private void initSpPosition(List<GetSimpleZoneBuffer> getSimpleZoneBuffers, NiceSpinner spPosition) {
        ArrayList<String> list = new ArrayList<String>();
        for (int i = 0; i < getSimpleZoneBuffers.size(); i++) {
            list.add(String.valueOf(
                    new StringBuilder()
                            .append(getSimpleZoneBuffers.get(i).getBuffer_name())
            ));
        }
        mSelectedBufferId = getSimpleZoneBuffers.get(0).getId();
        mSelectedBufferName = getSimpleZoneBuffers.get(0).getBuffer_name();
        spPosition.attachDataSource(list);
        spPosition.addOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                mSelectedBufferId = getSimpleZoneBuffers.get(position).getId();
                mSelectedBufferName = getSimpleZoneBuffers.get(position).getBuffer_name();
            }
        });
    }

    /**
     * @param
     * @return
     * @method
     * @description agv发运
     * @date: 2020/9/3 0003 23:19
     * @author: 小星
     */
    private void sendAGVFromMaskToTestOrder(FengQianLieBiao fengQianLieBiao) {
        showLoading();

        String methodNames = "SendAGVFromMaskToTestOrder";
        SoapParams paramss = null;
        paramss = new SoapParams();
        paramss.put("mid", fengQianLieBiao.getMid());
        paramss.put("monthid", fengQianLieBiao.getMonthid());
        paramss.put("to_buffer", mSelectedBufferName);

        SoapUtil.getInstance(getContext()).callEntry(getUrl(), BaseConstants.NAME_SPACE, methodNames, paramss, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {
                hideLoading();
                try {
                    String result = object.getProperty(methodNames + "Result").toString();
                    if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100") && !result.equals("false")) {
                        showMessage("AGV发运成功");
                        maskListForQuality();
                    } else {
                        showMessage("AGV发运失败");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
                hideLoading();
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
                hideLoading();

            }
        }, getAapiUserName(), getApiPwd());
    }

    /**
     * @param
     * @return
     * @method
     * @description 人工发运
     * @date: 2020/9/3 0003 23:19
     * @author: 小星
     */
    private void peopleSendFromMaskToTestOrder(FengQianLieBiao fengQianLieBiao) {
        showLoading();

        String methodNames = "PeopleSendFromMaskToTestOrder";
        SoapParams paramss = null;
        paramss = new SoapParams();
        paramss.put("mid", fengQianLieBiao.getMid());
        paramss.put("monthid", fengQianLieBiao.getMonthid());
        paramss.put("to_buffer", mSelectedBufferName);

        SoapUtil.getInstance(getContext()).callEntry(getUrl(), BaseConstants.NAME_SPACE, methodNames, paramss, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {
                hideLoading();
                try {
                    String result = object.getProperty(methodNames + "Result").toString();
                    if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100") && !result.equals("false")) {
                        showMessage("人工发运成功");
                        maskListForQuality();
                    } else {
                        showMessage("人工发运失败");
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
                hideLoading();
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
                hideLoading();

            }
        }, getAapiUserName(), getApiPwd());
    }

    /**
     * @param
     * @return
     * @method
     * @description 生成封签码
     * @date: 2020/9/3 0003 21:56
     * @author: 小星
     */
    private void createMaskCode(String monthid) {
        showLoading();
        int random = new Random().nextInt(100);
        String methodNames = "CreateMaskCode";
        SoapParams paramss = null;
        paramss = new SoapParams();
        paramss.put("simpleCode", monthid + "_" + random);
        SoapUtil.getInstance(getContext()).callEntry(getUrl(), BaseConstants.NAME_SPACE, methodNames, paramss, new SoapListener() {
            @Override
            public void onSuccess(int statusCode, SoapObject object) {
                hideLoading();
                try {
                    String result = object.getProperty(methodNames + "Result").toString();
                    if (result != null && !result.equals("[]") && !result.equals("anyType{}") && !result.equals("Error") && !result.equals("-100")) {
                        //打印二维码
                        printBigQRcodeOriention(result);
                    } else {

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, String content, Throwable error) {
                hideLoading();
            }

            @Override
            public void onFailure(int statusCode, SoapFault fault) {
                hideLoading();

            }
        }, getAapiUserName(), getApiPwd());
    }

    public static void printBigQRcodeOriention(String content) {

        // 得到 IDzPrinter 对象
        IDzPrinter printer = IDzPrinter.Factory.getInstance();
        // 连接配对的第一个打印机对象
        printer.connect(IDzPrinter.Factory.getFirstPrinter());
        // 创建 IAtBitmap 绘图对象
        IAtBitmap api = IAtBitmap.Factory.createInstance();
        // 开始绘图任务，传入参数(页面宽度, 页面高度)
        api.setItemHorizontalAlignment(LPAPI.ItemAlignment.LEFT);
        api.setItemOrientation(180);

        api.startJob(50 * 100, 50 * 100);//48, 50
//        api.setItemOrientation(180);
//        api.drawText("封签码:" + content, 40 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
        api.drawText("封签码", 27 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
        api.draw2DQRCode(content, 14 * 100, 13 * 100, 20 * 100);//  9, 10, 20,30
//        // 开始一个页面的绘制，绘制二维码
//        if (name.length() > 19) {
//            if (name.substring(19).length() > 23) {
//                api.drawText("入库时间:" + time, 46 * 100, 4 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("" + name.substring(42), 46 * 100, 7 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("" + name.substring(19, 42), 46 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("物料名称:" + name.substring(0, 19), 46 * 100, 13 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("项目编号:" + proid, 46 * 100, 16 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("核对序号:" + content, 46 * 100, 19 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
////                api.drawText("数量:" + num, 16 * 100, 12 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
//                api.drawText("订单号:" + orderNo, 46 * 100, 22 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.draw2DQRCode(content, 14 * 100, 23 * 100, 17 * 100);//  9, 10, 20,30
//            } else {
//                api.drawText("入库时间:" + time, 46 * 100, 4 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("" + name.substring(19), 46 * 100, 7 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("物料名称:" + name.substring(0, 19), 46 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("项目编号:" + proid, 46 * 100, 13 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.drawText("核对序号:" + content, 46 * 100, 16 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
////                api.drawText("数量:" + num, 16 * 100, 9 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
//                api.drawText("订单号:" + orderNo, 46 * 100, 19 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//                api.draw2DQRCode(content, 14 * 100, 20 * 100, 20 * 100);//  9, 10, 20,30
//            }
//
//        } else {
//            api.drawText("入库时间:" + time, 46 * 100, 4 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//            api.drawText("物料名称:" + name, 46 * 100, 7 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//            api.drawText("项目编号:" + proid, 46 * 100, 10 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//            api.drawText("核对序号:" + content, 46 * 100, 13 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
////            api.drawText("数量:" + num, 16 * 100, 6 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR);
//            api.drawText("订单号:" + orderNo, 46 * 100, 16 * 100, 0, 0, 2 * 100, IAtBitmap.FontStyle.REGULAR, 0);
//            api.draw2DQRCode(content, 14 * 100, 17 * 100, 20 * 100);//  9, 10, 20,30
//        }

        // 结束绘图任务
        api.endJob();
        // 打印
        printer.print(api, null);

    }

    @Override
    public void onProgressInfo(String info) {

    }

    @Override
    public void onStateChange(String info) {

    }

    @Override
    public void onPrintProgress(String info) {

    }

    @Override
    public void onPrinterDiscovery(String info) {

    }

    @Override
    public void connectSuccess(String info) {

    }

    @Override
    public void Connecting(String info) {

    }

    @Override
    public void connectFail(String info) {

    }

    @Override
    public void printSuccess() {

    }

    @Override
    public void printFail() {

    }
}
